home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Shareware / Programare / nativej / nativej-trial.exe / {app} / examples-source / Gui.java < prev    next >
Text File  |  2004-12-14  |  2KB  |  52 lines

  1. package examples;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5.  
  6. /**
  7.  * This is a sample Java program that runs in GUI mode.
  8.  *
  9.  * It has two common characteristics of a typical Java graphical app:
  10.  *
  11.  * 1. The main() thread configures and displays the main window, then exits.
  12.  * 2. System.exit() is called when the termination event is received.
  13.  *
  14.  * Unfortunately calling System.exit() has the side effect of shutting
  15.  * down the entire native app.
  16.  *
  17.  * Take a look at Gui2.java to find out how to avoid using System.exit()
  18.  * to terminate your GUI app.
  19.  */
  20. public class Gui
  21. {
  22.     /**
  23.      * The main() thread configures and displays the main window, then exits.
  24.      */
  25.     public static void main(String[] args) throws Exception
  26.     {
  27.         // Create the main window and components used by this app
  28.         Frame frame = new Frame("Gui");
  29.         String msg = "Hello World!";
  30.         if (args.length > 0) msg = "Hello " + args[0] + "!";
  31.         Label label = new Label(msg, Label.CENTER);
  32.  
  33.         // Handle the exit event for the main window
  34.         frame.addWindowListener(new WindowAdapter()
  35.         {
  36.             public void windowClosing(WindowEvent e)
  37.             {
  38.                 System.exit(0);
  39.             }
  40.         });
  41.  
  42.         // Position the components within the main window
  43.         frame.setLayout(new BorderLayout());
  44.         frame.add(label, BorderLayout.CENTER);
  45.  
  46.         // Resize and show main window
  47.         frame.pack();
  48.         frame.setSize(320, 240);
  49.         frame.show();
  50.     }
  51. }
  52.